home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / language / nasm20 / nasm20s.zoo / asm65.y < prev    next >
Text File  |  1993-01-22  |  12KB  |  323 lines

  1. %{
  2. /* ---------------------------------------------------------------------- */
  3. /*                   Copyright (C) 1992 by Natürlich!                     */
  4. /*                      This file is copyrighted!                         */
  5. /*                Refer to the documentation for details.                 */
  6. /* ---------------------------------------------------------------------- */
  7. /*#define YYDEBUG*/
  8. #include <stdio.h>
  9. #include "defines.h"
  10. #undef DEBUG
  11. #include "structs.h"
  12. #include "nasm.h"
  13. #include "labels.h"
  14. #include "code.h"
  15. #include "buffer.h"
  16. #include "exprfast.h"
  17. #include "op.h"
  18.  
  19. #if DEBUG
  20. #define bputchar( c)   putchar( c)
  21. #define dbprintf( s)    puts( s)
  22. #else
  23. #define dbputchar( c)
  24. #define dbprintf( s)
  25. #endif
  26.  
  27. #ifdef NIL
  28. #undef NIL
  29. #endif
  30. #define NIL   ((char *) 0)
  31. #define ENIL  ((expr *) 0)
  32.  
  33. extern int     _in_instr,
  34.                _in_doteq,
  35.                _call_macro,
  36.                wasstrlen,
  37.                state,
  38.                fully_mac65;
  39.  
  40.  
  41. extern buffer huge   *bp;
  42. extern word    __pc;
  43.  
  44. static char    undefined[] = { 9, 0, 'u','n','d','e','f','i','n','e','d' },
  45.                *lastident;
  46. static int     footok;
  47. static lword   fooval;
  48. #define adrmod footok      /* screws the debugger of course (har har) */
  49.  
  50. typedef union
  51. {
  52.    lword     u;
  53.    byte     *b;
  54.    char     *c;
  55.    expr     *e;
  56.    lexpr    *l;
  57. } YYSTYPE;
  58.  
  59. #define _ul    lword
  60. %}
  61.  
  62. %start file
  63. /* ---------------------------------------------------------- */
  64. /*     The order of these tokens MIGHT be VERY IMPORTANT      */
  65. /* ---------------------------------------------------------- */
  66. %token <u>  T_DOTEQ  T_IF     T_ELSE   T_LOCAL  T_EOL    T_NUMBER T_ZEXT
  67. %token <u>  T_ENDIF  T_ORG    T_DS     T_WORD   T_BYTE   T_SBYTE  T_OPT
  68. %token <u>  T_MACRO  T_ENDM   T_END    T_NUM    T_OBJ    T_MLIST  T_INCLUDE
  69. %token <u>  T_ERROR  T_TITLE  T_DBYTE  T_TAB    T_FLOAT  T_CBYTE  T_XREF
  70. %token <u>  T_SET    T_LIST   T_ERR    T_ACCU   T_CHAR   T_NOT    T_DEF
  71. %token <u>  T_REF    T_CLIST  T_EJECT  T_PAGE   T_XFLOAT T_UNDEF  T_WARN
  72. %token <u>  T_REPT   T_CALL
  73. %token <c>  T_IDENT  T_STRING T_LABEL  T_FILE   
  74. %token <e>  T_EXPR
  75. %token <b>  T_INSTR
  76.  
  77. %type  <e>  irest    s_expr   a_expr   modif   __expr
  78. %type  <l>  t_expr   u_expr   si_expr  mi_expr  i_expr   fubar    ei_expr
  79.  
  80. %left     <e>  ','   T_NO        /* not really... */
  81. %left     <e>  T_OR
  82. %left     <e>  T_AND
  83. %nonassoc <e>  T_LEQ T_GEQ '=' T_NEQ '>' '<'
  84. %left          MIDDLE
  85. %left     <e>  '!'   '^'   '&'
  86. %left     <e>  '+'   '-'
  87. %left     <e>  '*'   '/'   '\\'
  88. %left          HIGHEST
  89.  
  90.  
  91. /* next five tokens are actually not used by YACC, but elsewhere */
  92. %token <u>  T_MPARA
  93. %token <c>  T_MSPARA
  94. %token <u>  T_MLPARA
  95. %token <c>  T_MLSPARA
  96. %token <l>  T_PARA
  97. %token      REALHIGH
  98.  
  99. %%
  100. file  :  source   line
  101.       |  source
  102.       ;
  103.  
  104. source:  source   sline
  105.             {
  106.                inc_line();
  107.                _in_instr = 0;
  108.                dbputchar( '\n');
  109.             }
  110.       |
  111.       |  error
  112.             {
  113.                nterror("unwanted token appeared", yychar);
  114.                while( (yychar = yylex()) && yychar != T_EOL);
  115.                inc_line();
  116.                if( ! yychar)
  117.                   return;
  118.                yyerrok;
  119.                yyclearin;
  120.             }
  121.       ;
  122.  
  123.  
  124. sline :  line     T_EOL
  125.       |  T_EOL
  126.       ;
  127.  
  128. line  :  T_LABEL
  129.                         {
  130.                            enter_pclabel( $1);
  131.                         }
  132.                   nline
  133.                         {
  134.                            dbprintf("T_LABEL nline [done with line]\n\n");
  135.                         }
  136.       |  T_LABEL  '=' '='  __expr
  137.                         {
  138.                            enter_elabel( $1, $4, L_ZERO | L_LINKZERO);
  139.                            dbprintf("T_LABEL == s_expr [done with line]\n\n");
  140.                         }
  141.       |  T_LABEL  '='      __expr
  142.                         {
  143.                            enter_elabel( $1, $3, L_NORMAL);
  144.                            dbprintf("T_LABEL = s_expr [done with line]\n\n");
  145.                         }
  146.       |  T_LABEL  T_DOTEQ  { _in_doteq = 1; }
  147.             __expr
  148.                         {
  149.                            _in_doteq = 0;
  150.                            enter_elabel( $1, $4, L_EQU);
  151.                            dbprintf("T_LABEL .= s_expr [done with line]\n\n");
  152.                         }
  153.       |  T_LABEL        {
  154.                            enter_pclabel( $1);
  155.                            dbprintf("T_LABEL [done with line]\n\n");
  156.                         }
  157.       |  nline          {
  158.                            dbprintf("regular line [done]\n\n");
  159.                         }
  160.       ;
  161.  
  162.  
  163. nline :  T_INSTR  {  _in_instr = 1;  }    irest
  164.                                           { generate( $1,adrmod,$3);}
  165.       |  T_IF     __expr                  { if_treat( $2);          }
  166.       |  T_ELSE                           { else_treat();           }
  167.       |  T_ENDIF                          { endif_treat();          }
  168.       |  T_ORG    __expr                  { setorg( $2, 0);         }
  169.       |  T_DS     __expr                  { reserve( $2);           }
  170.       |  T_WORD   i_expr                  { dropwords(  $2);        }
  171.       |  T_DBYTE  i_expr                  { dropdbytes( $2);        }
  172.       |  T_BYTE   modif    si_expr        { dropbytes(  $2, $3, 0); }
  173.       |  T_CBYTE  modif    si_expr        { dropbytes(  $2, $3, 1); }
  174.       |  T_SBYTE  modif    si_expr        { dropsbytes( $2, $3);    }
  175.       |  T_ZEXT   T_IDENT                 { page0decl( $2);         }
  176.       |  T_FLOAT  f_expr
  177.       |  T_CALL   T_IDENT                 { call_macro( $2);        }
  178.       |  T_IDENT                          { lastident = NIL; 
  179.                                             _call_macro = 1;        }
  180.             ei_expr                       { _call_macro = 0;
  181.                                             do_macro( $1, $3);      }
  182.       |  T_REPT   __expr   T_IDENT        { lastident = NIL;        
  183.                                             _call_macro = 1;        }
  184.             ei_expr                       { _call_macro = 0;
  185.                                             rept_macro( $2, $3, $5);}
  186.       |  T_TAB    i_expr                  { dbprintf("T_TAB");      }
  187.       |  T_OPT    o_expr                  { dbprintf("T_OPT");      }
  188.       |  T_SET    __expr   ','   __expr   { dbprintf("T_SET");      }
  189.       |  T_UNDEF  T_IDENT                 { undefine( $2);          }
  190.       |  T_MACRO  T_IDENT                 {
  191.                                              load_macro( $2);
  192.                                              dbprintf("*** DONE WITH .MACRO ***");
  193.                                           }
  194.       |  T_INCLUDE '#'     T_FILE         {
  195.                                              footok = yylex();
  196.                                              fooval = yylval.u;
  197.                                              include( $3, ".h65");
  198.                                              fix_include( footok, fooval);
  199.                                           }
  200.       |  T_END                            { return( 0);          }
  201.       |  T_LOCAL                          { do_local();          }
  202.       |  T_TITLE  T_STRING                { dbprintf("TITLE\n"); }
  203.       |  T_PAGE   T_STRING                { dbprintf("PAGE\n");  }
  204.       |  T_ERROR  T_STRING                { nerror( $2 + 2);     }
  205.       |  T_WARN   T_STRING                { nwarning( $2 + 2);   }
  206.       ;
  207.  
  208.  
  209. irest :  __expr   ','      'X'            { adrmod = C_RELX; }
  210.       |  __expr   ','      'Y'            { adrmod = C_RELY; }
  211.       |  '('      __expr   ','  'X'   ')' { adrmod = C_INDX; $$ = $2;   }
  212.       |  '('      __expr   ')'  ','   'Y' { adrmod = C_INDY; $$ = $2;   }
  213.       |  '#'      __expr                  { adrmod = C_IMM;  $$ = $2;   }
  214.       |  '('      __expr   ')'            { adrmod = C_IND;  $$ = $2;   }
  215.       |  __expr                           { adrmod = C_ABS;             }
  216.       |  T_ACCU                           { adrmod = C_ACCU; $$ = ENIL; }
  217.       |                                   { adrmod = C_IMPL; $$ = ENIL; }
  218.       ;
  219.  
  220. a_expr:   T_NUMBER                     { $$ = ival_pl( (word) $1);         }
  221.       |   T_IDENT                      { $$ = lval_pl( l